// OpenGL-freeGLUT-Keyboard-Interaction.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <gl\glew.h>
#include <gl\freeglut.h>

bool keyStates[256];

void MainLoop (void) 
{  
	if(keyStates['a'])
	{
		glClearColor(1.0, 0.0, 0.0, 1.0);
	}
	else
	{
		glClearColor(0, 0, 0, 1.0f);
	}
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();
  
	glutSwapBuffers();
}

void Reshape (int width, int height) 
{  
	glViewport(0, 0, (GLsizei)width, (GLsizei)height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0, 100.0);
	glMatrixMode(GL_MODELVIEW);
}

void KeyDown(unsigned char key, int x, int y)
{
	if(key < 93)
	{
		key+=32;
	}
	keyStates[key] = true;
}

void KeyUp(unsigned char key, int x, int y)
{
	if(key < 93)
	{
		key+=32;
	}
	keyStates[key] = false;
}

int _tmain(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode (GLUT_DOUBLE);
	glutInitWindowSize (500, 500);
	glutInitWindowPosition (100, 100);
	glutCreateWindow ("freeGLUT Keyboard Interaction");

	glutReshapeFunc(Reshape);
	glutDisplayFunc(MainLoop);
	glutIdleFunc(MainLoop);
	glutKeyboardFunc(KeyDown);
	glutKeyboardUpFunc(KeyUp);
  
	glutMainLoop();
	return 0;
}

